package com.englishtest.base.db;

import org.hibernate.Query;

import com.englishtest.base.Paginater;


public class HqlUtils {
	public static void appendAnd(StringBuffer hql) {
		appendString(hql, " and ");
	}
	public static void appendOr(StringBuffer hql) {
		appendString(hql, " or ");
	}
	
	private static void appendString(StringBuffer hql, String str) {
		if(hql != null && hql.length() > 0) {
			hql.append(str);
		}
	}
	
	public static void insertWhere(StringBuffer condition) {
        if(condition.length() != 0) {
            condition.insert(0, " where ");
        }
    }
	
	public static void setPaginaterFirstResultAndMaxResults(Query query, Paginater paginater) {
        if(paginater != null) {
            query.setFirstResult(paginater.getFirstResult());
            query.setMaxResults(paginater.getPageSize());
        }
    }
}
